<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");require_once("../config/pagecls.php");

if($action=='del'){
	$db->delete("{$db_prefix}applyzmd","id='$id'");
	echo "<script>location.href='user_zmdlst.php?pageno={$pageno}';</script>";exit();
}
if($action=='stop'){
	$sqlchk="select * from {$db_prefix}applyzmd where id='$id'";
	$rschk=$db->get_one($sqlchk);
	if ($rschk['state']!=1){
		$msg.="报单中心所处状态不能停止\\n";
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$sqlhy="select * from {$db_prefix}users where username='".$rschk['username']."'";
	$rshy=$db->get_one($sqlhy);
	
	$state=2;$edittime=$curtime;
	//更新数据库中
	$dataArray['state']=$state;
	$dataArray['edittime']=$edittime;
	$condition="id='$id'";
	$db->update("{$db_prefix}applyzmd",$dataArray,$condition);
	
	//更新用户的级别
	$sqlgx="update {$db_prefix}users set isdp=0 where id='".$rshy['id']."'";
	$db->query($sqlgx);	
	echo "<script>alert('会员{$rschk['username']}的报单中心停止成功'); location.href = 'user_zmdlst.php?pageno={$pageno}'; </script>";exit();
}
if($action=='start'){
	$sqlchk="select * from {$db_prefix}applyzmd where id='$id'";
	$rschk=$db->get_one($sqlchk);
	if ($rschk['state']!=2){
		$msg.="报单中心所处状态不能启用\\n";
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$sqlhy="select * from {$db_prefix}users where username='".$rschk['username']."'";
	$rshy=$db->get_one($sqlhy);
	
	$state=1;$edittime=$curtime;
	//更新数据库中
	$dataArray['state']=$state;
	$dataArray['edittime']=$edittime;
	$condition="id='$id'";
	$db->update("{$db_prefix}applyzmd",$dataArray,$condition);
	
	//更新用户的级别
	$sqlgx="update {$db_prefix}users set isdp=1 where id='".$rshy['id']."'";
	$db->query($sqlgx);	
	echo "<script>alert('会员{$rschk['username']}的报单中心启用成功'); location.href = 'user_zmdlst.php?pageno={$pageno}'; </script>";exit();
}
if($action=='shenhe'){
	$sqlchk="select * from {$db_prefix}applyzmd where id='$id'";
	$rschk=$db->get_one($sqlchk);
	if ($rschk['state']>0){
		$msg.="升级申请已经处理\\n";
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$sqlhy="select * from {$db_prefix}users where username='".$rschk['username']."'";
	$rshy=$db->get_one($sqlhy);
	
	//本次需要多少报单款
	$sjneedprice=$glo_bdzxprice;
	$state=1;$edittime=$curtime;
	//升级是否扣报单款
	if ($glo_zmdsqkbdprice==1){
		if ($rshy['price']<$sjneedprice){
			$msg.="本次申请需要{$sjneedprice}美金\\n\\n会员{$rshy['username']}的报单币不足\\n";
			echo "<script>alert('$msg');history.back();</script>";exit();
		}
		//扣除会员的报单币
		$sqlkk="update {$db_prefix}users set price=price-'$sjneedprice' where id='".$rshy['username']."'";
		$db->query($sqlkk);
		//财务记录
		$e_userid=$rshy['id'];$e_price=-$sjneedprice;$e_type=8;$e_ptype=1;$e_addtime=$curtime;$e_memo="申请报单中心";
		hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	}
	//更新数据库中
	$dataArray['state']=$state;
	$dataArray['edittime']=$edittime;
	$condition="id='$id'";
	$db->update("{$db_prefix}applyzmd",$dataArray,$condition);
	
	//更新用户的级别
	$sqlgx="update {$db_prefix}users set isdp=1,zmdname='".$rschk['zmdname']."',zmdrank='".$rschk['zmdrank']."',zmdprovince='".$rschk['zmdprovince']."',zmdcity='".$rschk['zmdcity']."',zmdarea='".$rschk['zmdarea']."',zmdaddress='".$rschk['zmdaddress']."' where id='".$rshy['id']."'";
	$db->query($sqlgx);
	
echo "<script>alert('会员{$rschk['username']}的报单中心申请成功');location.href='user_zmdlst.php?pageno={$pageno}';</script>";exit();
}

if($action=='jujue'){
	$sqlchk="select * from {$db_prefix}applyzmd where id='$id'";
	$rschk=$db->get_one($sqlchk);
	if ($rschk['state']>0){
		$msg.="升级申请已经处理\\n";
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//更新数据库中
	$dataArray['state']=0;
	$dataArray['edittime']=$curtime;
	$condition="id='$id'";
	$db->update("{$db_prefix}applyzmd",$dataArray,$condition);
	echo "<script>alert('会员{$rschk['username']}的报单中心申请已拒绝');location.href='user_zmdlst.php?pageno={$pageno}';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="../calendar/WdatePicker.js"></script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
font-size:12px;
}
.red{
	color:#FF0000
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">报单中心申请</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td align="center" class="left_bt2"><form name="form1" method="post" action="?action=query">
                    会员：
                    <label>
      <input name="username" type="text" id="username" size="5">
      </label>
      <label></label>
      <label>状态：
        <select name="state">
        <option value="">全部状态</option>
        <option value="0">未处理</option>
        <option value="1">已升级</option>
        <option value="2">已拒绝</option>
      </select>
        时间：
  <input name="time1" type="text" id="time1" size="8" onClick="WdatePicker()">
        -
  <input name="time2" type="text" id="time2" size="8" onClick="WdatePicker()">
      </label>
      <label></label>
      <label>
      <input type="submit" name="Submit" value="查询">
      </label>
                                                      </form></td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30"><table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >会员</td>
                  <td align="center" bgcolor="#f2f2f2" >报单中心名称</td>
                  <td align="center" bgcolor="#f2f2f2" >申请报单中心级别</td>
                  <td align="center" bgcolor="#f2f2f2" >报单中心地区</td>
                  <td align="center" bgcolor="#f2f2f2" >报单中心详细地址</td>
                  <td align="center" bgcolor="#f2f2f2" >状态</td>
                  <td align="center" bgcolor="#f2f2f2" >申请时间</td>
                  <td align="center" bgcolor="#f2f2f2" >审核时间</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
  <?
  $query='';
  if ($action=='query'){
  	if (trim($username)!='') $query.=" and username='".trim($username)."'";
	if (trim($state)!='') $query.=" and state='".trim($state)."'";
	if (trim($time1)!='') $query.=" and addtime>='".strtotime($time1)."'";
	if (trim($time2)!='') $query.=" and addtime<='".(strtotime($time1)+24*3600)."'";
  }
  $sql="select count(id) as c  from {$db_prefix}applyzmd where 1";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}applyzmd where 1";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>
                  <td align="center"><?=$rs['username']?></td>
                  <td align="center"><?=$rs['zmdname']?></td>
                  <td align="center"><?=$zmdrankary[$rs['zmdrank']]?></td>
                  <td align="center"><?=getprovince($rs['zmdprovince']).'-'.getcity($rs['zmdcity']).'-'.getarea($rs['zmdarea'])?></td>
                  <td align="center"><?=$rs['zmdaddress']?></td>
                  <td align="center" ><? if($rs['state']==0) echo "未处理";elseif($rs['state']==1) echo "已升级";else echo "已拒绝";?></td>
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                  <td align="center" ><? if ($rs['edittime']>0) echo date("Y-m-d H:i:s",$rs['edittime'])?></td>
                  <td height="30" align="center" >
				  <?
				  if ($rs['state']==0){
				  ?>
				  <a href="?action=shenhe&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定要审核吗？')">审核</a>|<a href="?action=jujue&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定要拒绝吗？')">拒绝</a>|
				  <?
				  }
				  if ($rs['state']==1){
				  ?>
				  <a href="?action=stop&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定要拒绝吗？')">停止</a>|
				  <?
				  }
				  if ($rs['state']==2){
				  ?>
				 <a href="?action=start&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定要拒绝吗？')">启用</a>|
				  <?
				  }
				  ?>
				  <a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">删除</a></td>
                  </tr>
	<?
  }
  $db->free_result($result);
  ?>
              </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right">每页<?=$page->pagesize?>条 第<?=$page->pageno?>/<?=$page->pagenum?>页 共<?=$page->recnum?>条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
